﻿#include "login_dialog.h"



Login_Dialog::Login_Dialog()
{
	this->resize(300, 500);
	QGridLayout* qgridLayout = new QGridLayout();
	this->setLayout(qgridLayout);

	int index = 0;
    m_state_label = new QLabel(this);
    m_state_label->move(105,40);
    m_state_label->setFixedSize(100,30);
    m_state_label->setText(("Login out"));

	qgridLayout->addWidget(m_state_label, index, 0);
	index++;





	QLabel* p = new QLabel(this);
	p->setText(("level:"));
	qgridLayout->addWidget(p, index, 0);
	


    m_qcombox_level = new QComboBox(this);
    m_qcombox_level->addItem("user");
    m_qcombox_level->addItem("admin");
	qgridLayout->addWidget(m_qcombox_level, index, 1);
	index++;
    connect(m_qcombox_level, &QComboBox::currentTextChanged, this, &Login_Dialog::currentChanged);


    p = new QLabel(this);
    p->setText("User");
    qgridLayout->addWidget(p, index, 0);
    m_user_edit = new QLineEdit(this);
    m_user_edit->setPlaceholderText(("Input User"));
    qgridLayout->addWidget(m_user_edit, index, 1);
    index++;


    p = new QLabel(this);
    p->setText("Password");
    qgridLayout->addWidget(p, index, 0);

    m_passward_edit = new QLineEdit(this);
    m_passward_edit->setPlaceholderText(("Input Password"));
    m_passward_edit->setEchoMode(QLineEdit::Password);
	qgridLayout->addWidget(m_passward_edit, index, 1);
	index++;


    m_login_button = new QPushButton(this);
    m_login_button->setText(("Login"));
	qgridLayout->addWidget(m_login_button, index, 0,1,2);
	index++;

    m_exit_button = new QPushButton(this);
    m_exit_button->setText(("Exit"));
    connect(m_exit_button,&QPushButton::clicked,this,&::Login_Dialog::hide);
	qgridLayout->addWidget(m_exit_button, index, 0,1,2);
	index++;
}


void Login_Dialog::currentChanged(const QString &text)
{
    if(text=="user")
    {
        m_user_edit->setDisabled(false);
    }
    if(text=="admin")
    {
        m_user_edit->setDisabled(true);
    }
}
